//
//  NewsViewController.m
//  HealthA段
//
//  Created by dllo on 15/6/3.
//  Copyright (c) 2015年 www.lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "NewsViewController.h"
#import "AFHTTPRequestOperationManager.h"
#import "UIImageView+WebCache.h"
#import "DetailNewsViewController.h"
#import "Medicine.h"
#import "Life.h"
#import "Drug.h"
#import "foodModel.h"
#import "DiseaseModel.h"
#import "MedecineCell.h"
#import "MJRefresh.h"
#import "Singleton.h"
#import "CollectViewController.h"
#import "SeacherViewController.h"
#import "AboutUsViewController.h"


#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height
@interface NewsViewController ()<UIScrollViewDelegate>
@property(nonatomic,retain)UISearchBar *SearchBar;
@property(nonatomic,retain)NSArray *headArr;
@property(nonatomic,retain)UIScrollView *headScrollerView;
@property(nonatomic,retain)UIScrollView *mainScrollerView;
@property(nonatomic,retain)UIView *medicineView;//医药新闻视图
@property(nonatomic,retain)UIView *lifeView;//生活贴士视图
@property(nonatomic,retain)UIView *drugView;//药品新闻视图
@property(nonatomic,retain)UIView *foodView;//食品新闻视图
@property(nonatomic,retain)UIView *dieaseView;//疾病快讯视图
@property(nonatomic,retain)UIScrollView *medScrollerView;
@property(nonatomic,retain)UITableView *medTableView;
@property(nonatomic,retain)NSMutableArray *meiArr;
@property(nonatomic,retain)NSMutableArray *metableArr;
@property(nonatomic,retain)UIPageControl *medPageControl;
@property(nonatomic,retain)Medicine *med;
@property(nonatomic,assign)NSInteger medPage;
@property(nonatomic,retain)UITableView *LifeTbaleView;
@property(nonatomic,retain)UIScrollView *lifeScrollerView;
@property(nonatomic,retain)NSMutableArray *lifeArr;
@property(nonatomic,retain)NSMutableArray *lifetableArr;
@property(nonatomic,retain)UIPageControl *lifePageControl;
@property(nonatomic,assign)NSInteger lifePage;
@property(nonatomic,retain)UITableView *drugTbaleView;
@property(nonatomic,retain)UIScrollView *drugScrollerView;
@property(nonatomic,retain)NSMutableArray *drugArr;
@property(nonatomic,retain)NSMutableArray *drugtableArr;
@property(nonatomic,retain)UIPageControl *drugPageControl;
@property(nonatomic,assign)NSInteger drugPage;
@property(nonatomic,retain)UITableView *foodTbaleView;
@property(nonatomic,retain)UIScrollView *foodScrollerView;
@property(nonatomic,retain)NSMutableArray *foodArr;
@property(nonatomic,retain)NSMutableArray *foodtableArr;
@property(nonatomic,retain)UIPageControl *foodPageControl;
@property(nonatomic,assign)NSInteger foodPage;
@property(nonatomic,retain)UITableView *dieaseTbaleView;
@property(nonatomic,retain)UIScrollView *dieaseScrollerView;
@property(nonatomic,retain)NSMutableArray *dieaseArr;
@property(nonatomic,retain)NSMutableArray *dieasetableArr;
@property(nonatomic,retain)UIPageControl *dieasePageControl;
@property(nonatomic,assign)NSInteger dieasePage;
@property(nonatomic,retain)UIView *SmallView;
@property(nonatomic,retain)UIView *backView;
@property(nonatomic,assign)BOOL LeftBuIsClick;
@property(nonatomic,retain)UITableView *smallTable;
@property(nonatomic,retain)NSArray *smallArr;
@property(nonatomic,assign)BOOL isNight;
@property(nonatomic, assign)NSInteger textCount;
@end

@implementation NewsViewController
-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.headArr = @[@"医药新闻",@"生活贴士",@"药品新闻",@"食品新闻",@"疾病快讯"];
        self.smallArr = @[@"夜间模式",@"收藏列表",@"清除缓存",@"关于我们"];
        self.meiArr = [NSMutableArray array];
        self.metableArr = [NSMutableArray array];
        self.lifeArr = [NSMutableArray array];
        self.lifetableArr = [NSMutableArray array];
        self.drugArr = [NSMutableArray array];
        self.drugtableArr = [NSMutableArray array];
        self.foodArr = [NSMutableArray array];
        self.foodtableArr = [NSMutableArray array];
        self.dieaseArr = [NSMutableArray array];
        self.dieasetableArr = [NSMutableArray array];
        self.drugPage = 1;
        self.medPage = 1;
        self.lifePage = 1;
        self.foodPage = 1;
        self.dieasePage = 1;
        self.LeftBuIsClick = YES;
        self.isNight = NO;
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self creatheadView];
    [self creatMedicineView];
    [self medicineData];
    [self creatLIfeView];
    [self lifeData];
    [self creatDrugView];
    [self drugData];
    [self creatFoodView];
    [self foodData];
    [self creatdieaseView];
    [self dieaseData];
    
    //创建导航栏左键
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"iconfont-jiahao"] style:UIBarButtonItemStylePlain target:self action:@selector(clickLeftBu)];
    //创建左键点击视图
    self.SmallView = [[UIView alloc] initWithFrame:CGRectMake(20, 0, 0.5* WIDTH, 0.6*WIDTH)];
    [self.SmallView setBackgroundColor:[UIColor whiteColor]];
    self.SmallView.hidden = YES;
    [self.view addSubview:self.SmallView];
    self.smallTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 0.5*WIDTH, 0.6*WIDTH+10) style:UITableViewStylePlain];
    [self.smallTable setBackgroundColor:[UIColor blackColor]];
    [self.SmallView addSubview:self.smallTable];
    self.smallTable.rowHeight = 60;
    self.smallTable.delegate = self;
    self.smallTable.dataSource = self;
    
  //创建导航栏右键-搜索
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"iconfont-sousuo"] style:UIBarButtonItemStylePlain target:self action:@selector(clickRightBu)];
}

//创建导航分类视图
-(void)creatheadView
{
    self.headScrollerView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 0.1*WIDTH)];
    self.headScrollerView.backgroundColor = [UIColor colorWithRed:186/255.0 green:186/255.0 blue:186/255.0 alpha:1];
    self.headScrollerView.contentSize = CGSizeMake(WIDTH, 0.1*WIDTH);
    [self.view addSubview:self.headScrollerView];
    for (int i = 0; i < 5; i++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
        [button setTitle:self.headArr[i] forState:UIControlStateNormal];
        button.frame = CGRectMake(i*0.2*WIDTH, 0, 0.2*WIDTH, 0.1*WIDTH);
        button.layer.cornerRadius = 20;
        button.tag = i + 100;
        button.tintColor = [UIColor blackColor];
        [[self.view viewWithTag:100]setTintColor:[UIColor redColor]];
        [button addTarget:self action:@selector(ClickHeadBu:) forControlEvents:UIControlEventTouchUpInside];
        [self.headScrollerView addSubview:button];
    }
    //创建主视图
    self.mainScrollerView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0.1*WIDTH, WIDTH, HEIGHT-64-(0.1)*WIDTH-49)];
    self.mainScrollerView.contentSize = CGSizeMake(5*WIDTH, HEIGHT-64-(0.1)*WIDTH-49);
    [self.view sendSubviewToBack:self.mainScrollerView];
    self.mainScrollerView.pagingEnabled = YES;
    self.mainScrollerView.bounces = NO;
    [self.view addSubview:self.mainScrollerView];
    //设置代理
    self.mainScrollerView.delegate = self;
}


//创建医药新闻视图
- (void)creatMedicineView
{
//    [[Singleton shareSingleton] hiddenNO];
    self.medicineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-64-(0.1)*WIDTH-49)];
    self.medicineView.backgroundColor = [UIColor yellowColor];
    [self.mainScrollerView addSubview:self.medicineView];
    //医药新闻tableview
    self.medTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-64-(0.1)*WIDTH-49) style:UITableViewStylePlain];
    self.medTableView.rowHeight = 100;
    [self.medicineView addSubview:self.medTableView];
    self.medTableView.delegate = self;
    self.medTableView.dataSource = self;
    [self medpullup];

 
}

//创建生活贴士视图
- (void)creatLIfeView
{
    self.lifeView = [[UIView alloc] initWithFrame:CGRectMake(WIDTH,0,WIDTH, HEIGHT-64-(0.1)*WIDTH-49)];
    self.lifeView.backgroundColor = [UIColor orangeColor];
    [self.mainScrollerView addSubview:self.lifeView];
    //生活贴士tableview
    self.LifeTbaleView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-64-(0.1)*WIDTH-49) style:UITableViewStylePlain];
    self.LifeTbaleView.rowHeight = 100;
    [self.lifeView addSubview:self.LifeTbaleView];
    self.LifeTbaleView.delegate = self;
    self.LifeTbaleView.dataSource = self;
    [self lifepullup];
}

//创建药品新闻视图
- (void)creatDrugView
{
    self.drugView = [[UIView alloc] initWithFrame:CGRectMake(2*WIDTH,0,WIDTH, HEIGHT-64-(0.1)*WIDTH-49)];
    self.drugView.backgroundColor = [UIColor orangeColor];
    [self.mainScrollerView addSubview:self.drugView];
    //生活贴士tableview
    self.drugTbaleView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-64-(0.1)*WIDTH-49) style:UITableViewStylePlain];
    self.drugTbaleView.rowHeight = 100;
    [self.drugView addSubview:self.drugTbaleView];
    self.drugTbaleView.delegate = self;
    self.drugTbaleView.dataSource = self;
    [self drugpullup];
}

//创建食品新闻视图
- (void)creatFoodView
{
    self.foodView = [[UIView alloc] initWithFrame:CGRectMake(3*WIDTH,0,WIDTH, HEIGHT-64-(0.1)*WIDTH-49)];
    self.foodView.backgroundColor = [UIColor orangeColor];
    [self.mainScrollerView addSubview:self.foodView];
    //生活贴士tableview
    self.foodTbaleView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-64-(0.1)*WIDTH-49) style:UITableViewStylePlain];
    self.foodTbaleView.rowHeight = 100;
    [self.foodView addSubview:self.foodTbaleView];
    self.foodTbaleView.delegate = self;
    self.foodTbaleView.dataSource = self;
    [self foodpullup];
}

//创建疾病快讯视图
- (void)creatdieaseView
{
    
    self.dieaseView = [[UIView alloc] initWithFrame:CGRectMake(4*WIDTH,0,WIDTH, HEIGHT-64-(0.1)*WIDTH-49)];
    self.dieaseView.backgroundColor = [UIColor orangeColor];
    [self.mainScrollerView addSubview:self.dieaseView];
    //生活贴士tableview
    self.dieaseTbaleView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-64-(0.1)*WIDTH-49) style:UITableViewStylePlain];
    self.dieaseTbaleView.rowHeight = 100;
    [self.dieaseView addSubview:self.dieaseTbaleView];
    self.dieaseTbaleView.delegate = self;
    self.dieaseTbaleView.dataSource = self;
    [self dieasepullup];
  
}

//解析医药新闻数据
- (void)medicineData
{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:[NSString stringWithFormat:@"http://api.yi18.net/news/list?page=%ld&limit=20&id=2",self.medPage] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSMutableDictionary *dic = responseObject;
        NSMutableArray *arr = dic[@"yi18"];
        for (NSMutableDictionary *temp in arr) {
            Medicine *medicine = [[Medicine alloc] init];
            [medicine setValuesForKeysWithDictionary:temp];
            [self.metableArr addObject:medicine];
            [self.meiArr addObject:medicine];
        }
        for (int i = 0; i < self.meiArr.count; i++) {
            if ([self.meiArr[i] img] == nil) {
                [self.meiArr removeObjectAtIndex:i];
            }
        }
        for (int i = 0; i < self.metableArr.count; i++) {
            if ([self.metableArr[i]img] == nil) {
                [self.metableArr removeObjectAtIndex:i];
            }
        }
        if (self.metableArr.count > 0) {
            [[Singleton shareSingleton] hiddenYes];
        }
    [self.meiArr removeObjectsInRange:NSMakeRange(4, self.meiArr.count-5)];
    [self.metableArr removeObjectsInRange:NSMakeRange(0, 4)];
    [self addmedicineScorllerView];
    [self.medTableView reloadData];
    [self.medTableView.legendFooter endRefreshing];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"请求失败");
    }];
    self.medPage++;
}

- (void)addmedicineScorllerView
{
    self.medScrollerView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 0.5*WIDTH)];
    self.medScrollerView.backgroundColor = [UIColor whiteColor];
    self.medScrollerView.contentSize = CGSizeMake(5*WIDTH, 0.5*WIDTH);
    self.medScrollerView.pagingEnabled = YES;
    self.medScrollerView.bounces = NO;
//设置滚动条的样式
    self.medScrollerView.indicatorStyle = UIScrollViewIndicatorStyleBlack;
    //设置代理
    self.medScrollerView.delegate = self;
    self.medTableView.tableHeaderView = self.medScrollerView;
    //将图片URL放到数组中
    for (int i = 0; i < self.meiArr.count; i++) {
        Medicine *medmol = self.meiArr[i];
        NSString *str = [NSString stringWithFormat:@"http://www.yi18.net/%@",medmol.img];
        NSURL *url = [NSURL URLWithString:str];
        UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(i*WIDTH, 0, WIDTH, 0.5*WIDTH)];
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0.39*WIDTH, WIDTH, 45)];
       
        titleLabel.textColor = [UIColor whiteColor];
        titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
        titleLabel.text = [self.meiArr[i] title];
        titleLabel.backgroundColor = [UIColor colorWithRed:227/255.0 green:98/255.0 blue:98/255.0 alpha:1];
        [image addSubview:titleLabel];
        [image sd_setImageWithURL:url];
        [self.medScrollerView addSubview:image];
        [self.medTableView reloadData];
    }
    self.medPageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0.7*WIDTH, 0.43 * WIDTH, 100, 36)];
    self.medPageControl.currentPageIndicatorTintColor = [UIColor blackColor];
    self.medPageControl.pageIndicatorTintColor = [UIColor whiteColor];
    self.medPageControl.numberOfPages = 5;

    [self.medTableView bringSubviewToFront:self.medPageControl];
    [self.medTableView addSubview:self.medPageControl];
    
    [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(change) userInfo:nil repeats:YES];
    
    // 手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    
    //设置需要点击几次才会触发方法
    tap.numberOfTapsRequired = 1;
    // 设置手指个数
    tap.numberOfTouchesRequired = 1;
    // 把手势加入到图片上
    [_medScrollerView addGestureRecognizer:tap];
    
}


//解析生活贴士数据
- (void)lifeData
{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:[NSString stringWithFormat:@"http://api.yi18.net/news/list?page=%ld&limit=20&id=3",self.lifePage] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSMutableDictionary *dic = responseObject;
        NSMutableArray *arr = dic[@"yi18"];
        for (NSMutableDictionary *temp in arr) {
            Life *life = [[Life alloc] init];
            [life setValuesForKeysWithDictionary:temp];
            [self.lifetableArr addObject:life];
            [self.lifeArr addObject:life];
        }
        for (int i = 0; i < self.lifeArr.count; i++) {
            if ([self.lifeArr[i] img] == nil) {
                [self.lifeArr removeObjectAtIndex:i];
            }
        }
        for (int i = 0; i < self.lifetableArr.count; i++) {
            if ([self.lifetableArr[i]img] == nil) {
                [self.lifetableArr removeObjectAtIndex:i];
            }
        }
        [self.lifeArr removeObjectsInRange:NSMakeRange(4, self.lifeArr.count-5)];
        [self.lifetableArr removeObjectsInRange:NSMakeRange(0, 4)];
        [self addlifescroView];
        [self.LifeTbaleView reloadData];
        [self.LifeTbaleView.legendFooter endRefreshing];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"请求失败");
    }];
    self.lifePage++;
}

- (void)addlifescroView
{
    self.lifeScrollerView = [[UIScrollView alloc] initWithFrame:CGRectMake(WIDTH, 0, WIDTH, 0.5*WIDTH)];
    self.lifeScrollerView.backgroundColor = [UIColor whiteColor];
    self.lifeScrollerView.contentSize = CGSizeMake(5*WIDTH, 0.5*WIDTH);
    self.lifeScrollerView.pagingEnabled = YES;
    self.lifeScrollerView.bounces = NO;
    //设置滚动条的样式
    self.lifeScrollerView.indicatorStyle = UIScrollViewIndicatorStyleBlack;
    //设置代理
    self.lifeScrollerView.delegate = self;
    self.LifeTbaleView.tableHeaderView = self.lifeScrollerView;
    //将图片URL放到数组中
    for (int i = 0; i < self.lifeArr.count; i++) {
        Life *lifemol = self.lifeArr[i];
        NSString *str = [NSString stringWithFormat:@"http://www.yi18.net/%@",lifemol.img];
        NSURL *url = [NSURL URLWithString:str];
        UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(i*WIDTH, 0, WIDTH, 0.5*WIDTH)];
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0.39*WIDTH, WIDTH, 45)];
        titleLabel.textColor = [UIColor whiteColor];
        titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
        titleLabel.text = [self.lifeArr[i] title];
        titleLabel.backgroundColor = [UIColor colorWithRed:227/255.0 green:98/255.0 blue:98/255.0 alpha:1];
        [image addSubview:titleLabel];
        [image sd_setImageWithURL:url];
        [self.lifeScrollerView addSubview:image];
        [self.LifeTbaleView reloadData];
    }
    self.lifePageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0.7*WIDTH, 0.43 * WIDTH, 100, 36)];
    self.lifePageControl.currentPageIndicatorTintColor = [UIColor blackColor];
    self.lifePageControl.pageIndicatorTintColor = [UIColor whiteColor];
    self.lifePageControl.numberOfPages = 5;
    
    [self.LifeTbaleView bringSubviewToFront:self.lifePageControl];
    [self.LifeTbaleView addSubview:self.lifePageControl];
    
    [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(changeLife) userInfo:nil repeats:YES];
    
    // 手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionLIfe:)];
    
    //设置需要点击几次才会触发方法
    tap.numberOfTapsRequired = 1;
    // 设置手指个数
    tap.numberOfTouchesRequired = 1;
    // 把手势加入到图片上
    [_lifeScrollerView addGestureRecognizer:tap];
}

// 解析药品新闻数据
- (void)drugData
{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:[NSString stringWithFormat:@"http://api.yi18.net/news/list?page=%ld&limit=20&id=4",self.drugPage] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSMutableDictionary *dic = responseObject;
        NSMutableArray *arr = dic[@"yi18"];
        for (NSMutableDictionary *temp in arr) {
            Drug *drug = [[Drug alloc] init];
            [drug setValuesForKeysWithDictionary:temp];
            [self.drugtableArr addObject:drug];
            [self.drugArr addObject:drug];
        }
        for (int i = 0; i < self.drugArr.count; i++) {
            if ([self.drugArr[i] img] == nil) {
                [self.drugArr removeObjectAtIndex:i];
            }
        }
        for (int i = 0; i < self.drugtableArr.count; i++) {
            if ([self.drugtableArr[i]img] == nil) {
                [self.drugtableArr removeObjectAtIndex:i];
            }
        }
        [self.drugArr removeObjectsInRange:NSMakeRange(4, self.drugArr.count-5)];
        [self.drugtableArr removeObjectsInRange:NSMakeRange(0, 4)];
        [self adddrugscroView];
        [self.drugTbaleView reloadData];
        [self.drugTbaleView.legendFooter endRefreshing];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"请求失败");
    }];
    self.drugPage++;
}

- (void)adddrugscroView
{
    self.drugScrollerView = [[UIScrollView alloc] initWithFrame:CGRectMake(WIDTH*2, 0, WIDTH, 0.5*WIDTH)];
    self.drugScrollerView.backgroundColor = [UIColor whiteColor];
    self.drugScrollerView.contentSize = CGSizeMake(5*WIDTH, 0.5*WIDTH);
    self.drugScrollerView.pagingEnabled = YES;
    self.drugScrollerView.bounces = NO;
    //设置滚动条的样式
    self.drugScrollerView.indicatorStyle = UIScrollViewIndicatorStyleBlack;
    //设置代理
    self.drugScrollerView.delegate = self;
    self.drugTbaleView.tableHeaderView = self.drugScrollerView;
    //将图片URL放到数组中
    for (int i = 0; i < self.drugArr.count; i++) {
        Drug *drug = self.drugArr[i];
        NSString *str = [NSString stringWithFormat:@"http://www.yi18.net/%@",drug.img];
        NSURL *url = [NSURL URLWithString:str];
        UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(i*WIDTH, 0, WIDTH, 0.5*WIDTH)];
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0.39*WIDTH, WIDTH, 45)];
        titleLabel.textColor = [UIColor whiteColor];
        titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
        titleLabel.text = [self.drugArr[i] title];
        titleLabel.backgroundColor = [UIColor colorWithRed:227/255.0 green:98/255.0 blue:98/255.0 alpha:1];
        [image addSubview:titleLabel];
        [image sd_setImageWithURL:url];
        [self.drugScrollerView addSubview:image];
        [self.drugTbaleView reloadData];
    }
    self.drugPageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0.7*WIDTH, 0.43 * WIDTH, 100, 36)];
    self.drugPageControl.currentPageIndicatorTintColor = [UIColor blackColor];
    self.drugPageControl.pageIndicatorTintColor = [UIColor whiteColor];
    self.drugPageControl.numberOfPages = 5;
    
    [self.drugTbaleView bringSubviewToFront:self.drugPageControl];
    [self.drugTbaleView addSubview:self.drugPageControl];
    
    [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(changedrug) userInfo:nil repeats:YES];
    
    // 手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActiondrug:)];
    
    //设置需要点击几次才会触发方法
    tap.numberOfTapsRequired = 1;
    // 设置手指个数
    tap.numberOfTouchesRequired = 1;
    // 把手势加入到图片上
    [_drugScrollerView addGestureRecognizer:tap];
    
}

//解析食品新闻视图
- (void)foodData
{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:[NSString stringWithFormat:@"http://api.yi18.net/news/list?page=%ld&limit=20&id=5",self.foodPage] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSMutableDictionary *dic = responseObject;
        NSMutableArray *arr = dic[@"yi18"];
        for (NSMutableDictionary *temp in arr) {
            foodModel *food = [[foodModel alloc] init];
            [food setValuesForKeysWithDictionary:temp];
            [self.foodtableArr addObject:food];
            [self.foodArr addObject:food];
        }
        for (int i = 0; i < self.foodArr.count; i++) {
            if ([self.foodArr[i]img] == nil) {
                [self.foodArr removeObjectAtIndex:i];
            }
        }
        for (int i = 0; i < self.foodtableArr.count; i++) {
            if ([self.foodtableArr[i]img] == nil) {
                [self.foodtableArr removeObjectAtIndex:i];
            }
        }
        [self.foodArr removeObjectsInRange:NSMakeRange(4, self.foodArr.count-5)];
        [self.foodtableArr removeObjectsInRange:NSMakeRange(0, 4)];
        [self addfoodscroView];
        [self.foodTbaleView reloadData];
        [self.foodTbaleView.legendFooter endRefreshing];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"请求失败");
    }];
    self.foodPage++;
}

- (void)addfoodscroView
{
    self.foodScrollerView = [[UIScrollView alloc] initWithFrame:CGRectMake(WIDTH*3, 0, WIDTH, 0.5*WIDTH)];
    self.foodScrollerView.backgroundColor = [UIColor whiteColor];
    self.foodScrollerView.contentSize = CGSizeMake(5*WIDTH, 0.5*WIDTH);
    self.foodScrollerView.pagingEnabled = YES;
    self.foodScrollerView.bounces = NO;
    //设置滚动条的样式
    self.foodScrollerView.indicatorStyle = UIScrollViewIndicatorStyleBlack;
    //设置代理
    self.foodScrollerView.delegate = self;
    self.foodTbaleView.tableHeaderView = self.foodScrollerView;
    //将图片URL放到数组中
    for (int i = 0; i < self.foodArr.count; i++) {
        foodModel *food = self.foodArr[i];
        NSString *str = [NSString stringWithFormat:@"http://www.yi18.net/%@",food.img];
        NSURL *url = [NSURL URLWithString:str];
        UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(i*WIDTH, 0, WIDTH, 0.5*WIDTH)];
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0.39*WIDTH, WIDTH, 45)];
        titleLabel.textColor = [UIColor whiteColor];
        titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
        titleLabel.text = [self.foodArr[i] title];
        titleLabel.backgroundColor = [UIColor colorWithRed:227/255.0 green:98/255.0 blue:98/255.0 alpha:1];
        [image addSubview:titleLabel];
        [image sd_setImageWithURL:url];
        [self.foodScrollerView addSubview:image];
        [self.foodTbaleView reloadData];
    }
    self.foodPageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0.7*WIDTH, 0.43 * WIDTH, 100, 36)];
    self.foodPageControl.currentPageIndicatorTintColor = [UIColor blackColor];
    self.foodPageControl.pageIndicatorTintColor = [UIColor whiteColor];
    self.foodPageControl.numberOfPages = 5;
    
    [self.foodTbaleView bringSubviewToFront:self.foodPageControl];
    [self.foodTbaleView addSubview:self.foodPageControl];
    
    [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(changefood) userInfo:nil repeats:YES];
    
    // 手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionfood:)];
    
    //设置需要点击几次才会触发方法
    tap.numberOfTapsRequired = 1;
    // 设置手指个数
    tap.numberOfTouchesRequired = 1;
    // 把手势加入到图片上
    [_foodScrollerView addGestureRecognizer:tap];
 
}

//解析疾病快讯视图
- (void)dieaseData
{
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:[NSString stringWithFormat:@"http://api.yi18.net/news/list?page=%ld&limit=20&id=7",self.dieasePage] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSMutableDictionary *dic = responseObject;
        NSMutableArray *arr = dic[@"yi18"];
        for (NSMutableDictionary *temp in arr) {
            DiseaseModel *diease = [[DiseaseModel alloc] init];
            [diease setValuesForKeysWithDictionary:temp];
            [self.dieasetableArr addObject:diease];
            [self.dieaseArr addObject:diease];
        }
        for (int i = 0; i < self.dieaseArr.count; i++) {
            if ([self.dieaseArr[i]img] == nil) {
                [self.dieaseArr removeObjectAtIndex:i];
            }
        }
        for (int i = 0; i < self.dieasetableArr.count; i++) {
            if ([self.dieasetableArr[i]img] == nil) {
                [self.dieasetableArr removeObjectAtIndex:i];
            }
        }
        [self.dieaseArr removeObjectsInRange:NSMakeRange(4, self.dieaseArr.count-5)];
        [self.dieasetableArr removeObjectsInRange:NSMakeRange(0, 4)];
        [self adddieasescroView];
        [self.dieaseTbaleView reloadData];
        [self.dieaseTbaleView.legendFooter endRefreshing];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"请求失败");
    }];
    self.dieasePage++;
  
}

- (void)adddieasescroView
{
    
    self.dieaseScrollerView = [[UIScrollView alloc] initWithFrame:CGRectMake(WIDTH*4, 0, WIDTH, 0.5*WIDTH)];
    self.dieaseScrollerView.backgroundColor = [UIColor whiteColor];
    self.dieaseScrollerView.contentSize = CGSizeMake(5*WIDTH, 0.5*WIDTH);
    self.dieaseScrollerView.pagingEnabled = YES;
    self.dieaseScrollerView.bounces = NO;
    //设置滚动条的样式
    self.dieaseScrollerView.indicatorStyle = UIScrollViewIndicatorStyleBlack;
    //设置代理
    self.dieaseScrollerView.delegate = self;
    self.dieaseTbaleView.tableHeaderView = self.dieaseScrollerView;
    //将图片URL放到数组中
    for (int i = 0; i < self.dieaseArr.count; i++) {
        DiseaseModel *diease = self.dieaseArr[i];
        NSString *str = [NSString stringWithFormat:@"http://www.yi18.net/%@",diease.img];
        NSURL *url = [NSURL URLWithString:str];
        UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(i*WIDTH, 0, WIDTH, 0.5*WIDTH)];
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0.39*WIDTH, WIDTH, 45)];
        titleLabel.textColor = [UIColor whiteColor];
        titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
        titleLabel.text = [self.dieaseArr[i] title];
        titleLabel.backgroundColor = [UIColor colorWithRed:227/255.0 green:98/255.0 blue:98/255.0 alpha:1];
        [image addSubview:titleLabel];
        [image sd_setImageWithURL:url];
        [self.dieaseScrollerView addSubview:image];
        [self.dieaseTbaleView reloadData];
    }
    self.dieasePageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0.7*WIDTH, 0.43 * WIDTH, 100, 36)];
    self.dieasePageControl.currentPageIndicatorTintColor = [UIColor blackColor];
    self.dieasePageControl.pageIndicatorTintColor = [UIColor whiteColor];
    self.dieasePageControl.numberOfPages = 5;
    
    [self.dieaseTbaleView bringSubviewToFront:self.dieasePageControl];
    [self.dieaseTbaleView addSubview:self.dieasePageControl];
    
    [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(changediease) userInfo:nil repeats:YES];
    
    // 手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActiondiease:)];
    
    //设置需要点击几次才会触发方法
    tap.numberOfTapsRequired = 1;
    // 设置手指个数
    tap.numberOfTouchesRequired = 1;
    // 把手势加入到图片上
    [_dieaseScrollerView addGestureRecognizer:tap];
    
  
}
//导航分类栏Button的点击方法
- (void)ClickHeadBu:(UIButton *)button
{
    switch (button.tag) {
        case 100:
            self.mainScrollerView.contentOffset = CGPointMake(0, 0);
            [self ChangeButtonFontAndColorTag1:100 tag2:101 tag3:102 tag4:103 tag5:104];
            break;
        case 101:
            self.mainScrollerView.contentOffset = CGPointMake(WIDTH, 0);
            [self ChangeButtonFontAndColorTag1:101 tag2:100 tag3:102 tag4:103 tag5:104];
            break;
        case 102:
            self.mainScrollerView.contentOffset = CGPointMake(2*WIDTH, 0);
            [self ChangeButtonFontAndColorTag1:102 tag2:100 tag3:101 tag4:103 tag5:104];
            break;
        case 103:
            self.mainScrollerView.contentOffset = CGPointMake(3*WIDTH, 0);
            [self ChangeButtonFontAndColorTag1:103 tag2:100 tag3:101 tag4:102 tag5:104];
            break;
        case 104:
            self.mainScrollerView.contentOffset = CGPointMake(4*WIDTH, 0);
            [self ChangeButtonFontAndColorTag1:104 tag2:100 tag3:101 tag4:102 tag5:103];
            break;
    }
}

//结束滑动触发的方法
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    if (self.mainScrollerView.contentOffset.x == 0) {
        [self ChangeButtonFontAndColorTag1:100 tag2:101 tag3:103 tag4:104 tag5:102];
    }
    if (self.mainScrollerView.contentOffset.x == WIDTH) {
        [self ChangeButtonFontAndColorTag1:101 tag2:100 tag3:102 tag4:103 tag5:104];
    }
    if (self.mainScrollerView.contentOffset.x == 2*WIDTH) {
        [self ChangeButtonFontAndColorTag1:102 tag2:100 tag3:101 tag4:103 tag5:104];
    }
    if (self.mainScrollerView.contentOffset.x == 3*WIDTH) {
        [self ChangeButtonFontAndColorTag1:103 tag2:100 tag3:101 tag4:102 tag5:104];
    }
    if (self.mainScrollerView.contentOffset.x == 4*WIDTH) {
        [self ChangeButtonFontAndColorTag1:104 tag2:100 tag3:101 tag4:102 tag5:103];
    }
}

- (void)ChangeButtonFontAndColorTag1:(NSInteger)tag1 tag2:(NSInteger)tag2 tag3:(NSInteger)tag3 tag4:(NSInteger)tag4 tag5:(NSInteger)tag5
{
    [[self.view viewWithTag:tag1] setTintColor:[UIColor redColor]];
    [[self.view viewWithTag:tag2] setTintColor:[UIColor blackColor]];
    [[self.view viewWithTag:tag3] setTintColor:[UIColor blackColor]];
    [[self.view viewWithTag:tag4] setTintColor:[UIColor blackColor]];
    [[self.view viewWithTag:tag5] setTintColor:[UIColor blackColor]];
}


#pragma mark TableView 两个协议方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView == self.medTableView) {
        return self.metableArr.count;
    }else if(tableView == self.LifeTbaleView){
        return self.lifetableArr.count;
    }else if(tableView == self.drugTbaleView){
        return self.drugtableArr.count;
    }else if(tableView == self.foodTbaleView){
        return self.foodtableArr.count;
    }else if(tableView == self.dieaseTbaleView){
        return self.dieasetableArr.count;
    }else{
        return 4;
    }
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == self.medTableView) {
        
        static NSString *reuse = @"medicine";
        MedecineCell * cell = [tableView dequeueReusableCellWithIdentifier:reuse];
        if (cell == nil) {
            cell = [[MedecineCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse];
        }
        cell.medcineText.text = [self.metableArr[indexPath.row]title];
//        cell.seeLabel.text = [NSString stringWithFormat:@"浏览:%@",[self.metableArr[indexPath.row]count]];
        NSString *str = [NSString stringWithFormat:@"http://www.yi18.net/%@",[self.metableArr[indexPath.row] img]];
        NSURL *url = [NSURL URLWithString:str];
        [cell.medcineImg sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"占位图"]];
        return cell;
    }else if(tableView == self.LifeTbaleView){
        static NSString *reuse = @"life";
        MedecineCell * cell = [tableView dequeueReusableCellWithIdentifier:reuse];
        if (cell == nil) {
            cell = [[MedecineCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse];
        }
        cell.medcineText.text = [self.lifetableArr[indexPath.row]title];
//        cell.seeLabel.text = [NSString stringWithFormat:@"浏览:%@",[self.lifetableArr[indexPath.row]count]];
        NSString *str = [NSString stringWithFormat:@"http://www.yi18.net/%@",[self.lifetableArr[indexPath.row] img]];
        NSURL *url = [NSURL URLWithString:str];
        [cell.medcineImg sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"占位图"]];
        return cell;
    }else if(tableView == self.drugTbaleView){
        static NSString *reuse = @"drug";
        MedecineCell * cell = [tableView dequeueReusableCellWithIdentifier:reuse];
        if (cell == nil) {
            cell = [[MedecineCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse];
        }
        cell.medcineText.text = [self.drugtableArr[indexPath.row]title];
//        cell.seeLabel.text = [NSString stringWithFormat:@"浏览:%@",[self.drugtableArr[indexPath.row]count]];
        NSString *str = [NSString stringWithFormat:@"http://www.yi18.net/%@",[self.drugtableArr[indexPath.row] img]];
        NSURL *url = [NSURL URLWithString:str];
        [cell.medcineImg sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"占位图"]];
        return cell;
    }else if(tableView == self.foodTbaleView){
        static NSString *reuse = @"food";
        MedecineCell * cell = [tableView dequeueReusableCellWithIdentifier:reuse];
        if (cell == nil) {
            cell = [[MedecineCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse];
        }
        cell.medcineText.text = [self.foodtableArr[indexPath.row]title];
//        cell.seeLabel.text = [NSString stringWithFormat:@"浏览:%@",[self.foodtableArr[indexPath.row]count]];
        NSString *str = [NSString stringWithFormat:@"http://www.yi18.net/%@",[self.foodtableArr[indexPath.row] img]];
        NSURL *url = [NSURL URLWithString:str];
        [cell.medcineImg sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"占位图"]];
        return cell;
    }else if(tableView == self.dieaseTbaleView){
        static NSString *reuse = @"diease";
        MedecineCell * cell = [tableView dequeueReusableCellWithIdentifier:reuse];
        if (cell == nil) {
            cell = [[MedecineCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse];
        }
        cell.medcineText.text = [self.dieasetableArr[indexPath.row]title];
//        cell.seeLabel.text = [NSString stringWithFormat:@"浏览:%@",[self.dieasetableArr[indexPath.row]count]];
        NSString *str = [NSString stringWithFormat:@"http://www.yi18.net/%@",[self.dieasetableArr[indexPath.row] img]];
        NSURL *url = [NSURL URLWithString:str];
        [cell.medcineImg sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"占位图"]];
        return cell;
    }else{
        static NSString *reuse = @"small";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuse] autorelease];
        }
        if (indexPath.row == 0) {
            if (self.isNight == NO) {
                cell.textLabel.text = @"夜间模式";
            }else{
                cell.textLabel.text = @"日间模式";
            }
        }else if (indexPath.row == 1){
            cell.textLabel.text = @"收藏列表";
        }else if (indexPath.row == 2){
            cell.textLabel.text = @"清除缓存";
        }else{
            cell.textLabel.text = @"关于我们";
        }
        cell.backgroundColor = [UIColor clearColor];
        cell.textLabel.textColor = [UIColor whiteColor];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    DetailNewsViewController *denewVC = [[DetailNewsViewController alloc] init];
    if (tableView == self.LifeTbaleView) {
        denewVC.titleName = [self.lifetableArr[indexPath.row] title];
        denewVC.myID = [self.lifetableArr[indexPath.row]id];
        [self.navigationController pushViewController:denewVC animated:YES];
    }else if(tableView == self.medTableView){
        denewVC.titleName = [self.metableArr[indexPath.row] title];
        denewVC.myID = [self.metableArr[indexPath.row]id];
        [self.navigationController pushViewController:denewVC animated:YES];
    }else if(tableView == self.drugTbaleView){
        denewVC.titleName = [self.drugtableArr[indexPath.row] title];
        denewVC.myID = [self.drugtableArr[indexPath.row]id];
        [self.navigationController pushViewController:denewVC animated:YES];
    }else if (tableView == self.foodTbaleView){
        denewVC.titleName = [self.foodtableArr[indexPath.row] title];
        denewVC.myID = [self.foodtableArr[indexPath.row]id];
        [self.navigationController pushViewController:denewVC animated:YES];
    }else if (tableView == self.dieaseTbaleView){
        denewVC.titleName = [self.dieasetableArr[indexPath.row] title];
        denewVC.myID = [self.dieasetableArr[indexPath.row]id];
        [self.navigationController pushViewController:denewVC animated:YES];
    }else{
        if (indexPath.row == 0) {
            if (self.isNight == NO) {
                [[Singleton shareSingleton]night];
                self.isNight = YES;
                [self.smallTable reloadData];
            }else{
                [[Singleton shareSingleton]day];
                self.isNight = NO;
                [self.smallTable reloadData];
            }
        }else if (indexPath.row == 1){
            CollectViewController *cvc = [[CollectViewController alloc]init];
            [self.navigationController pushViewController:cvc animated:YES];
            [cvc release];
        }else if (indexPath.row == 2){
            NSFileManager *manager = [NSFileManager defaultManager];
            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
            NSString *path = [paths lastObject];
            NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:path];
            for (NSString *p in files) {
                NSString *pathi = [path stringByAppendingPathComponent:p];
                [manager removeItemAtPath:pathi error:nil];
                self.textCount = files.count;
            }
            if (self.textCount > 3) {
                NSString *text = [NSString stringWithFormat:@"已成功清除%ld个缓存文件",self.textCount];
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:text delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
                [alert show];
            }
            else {
                UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"提示" message:@"已全部清除完成" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
                [alert show];
            }
           
        }else if (indexPath.row == 3){
            AboutUsViewController *usview = [[AboutUsViewController alloc]init];
            [self.navigationController pushViewController:usview animated:YES];
            [usview release];
        }
    }
}


- (void)change
{
    NSInteger dx = self.medScrollerView.contentOffset.x;
    NSInteger pageNum = dx / WIDTH;
    if (pageNum != 4) {
        self.medScrollerView.contentOffset = CGPointMake(dx + WIDTH, 0);
    }else{
        self.medScrollerView.contentOffset = CGPointMake(0, 0);
    }
}

- (void)changeLife
{
    NSInteger dx = self.lifeScrollerView.contentOffset.x;
    NSInteger pageNum = dx / WIDTH;
    if (pageNum != 4) {
        self.lifeScrollerView.contentOffset = CGPointMake(dx + WIDTH, 0);
    }else{
        self.lifeScrollerView.contentOffset = CGPointMake(0, 0);
    }
}

- (void)changedrug
{
    NSInteger dx = self.drugScrollerView.contentOffset.x;
    NSInteger pageNum = dx / WIDTH;
    if (pageNum != 4) {
        self.drugScrollerView.contentOffset = CGPointMake(dx + WIDTH, 0);
    }else{
        self.drugScrollerView.contentOffset = CGPointMake(0, 0);
    }
}

- (void)changefood
{
    NSInteger dx = self.foodScrollerView.contentOffset.x;
    NSInteger pageNum = dx / WIDTH;
    if (pageNum != 4) {
        self.foodScrollerView.contentOffset = CGPointMake(dx + WIDTH, 0);
    }else{
        self.foodScrollerView.contentOffset = CGPointMake(0, 0);
    }
}

- (void)changediease
{
    
    NSInteger dx = self.dieaseScrollerView.contentOffset.x;
    NSInteger pageNum = dx / WIDTH;
    if (pageNum != 4) {
        self.dieaseScrollerView.contentOffset = CGPointMake(dx + WIDTH, 0);
    }else{
        self.dieaseScrollerView.contentOffset = CGPointMake(0, 0);
    }
  
}
//设置当前的PageControl
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (scrollView == self.medScrollerView) {
        NSInteger pageNum = self.medScrollerView.contentOffset.x / WIDTH;
        self.medPageControl.currentPage = pageNum;
    }
    if (scrollView == self.lifeScrollerView) {
        NSInteger pageNum = self.lifeScrollerView.contentOffset.x / WIDTH;
        self.lifePageControl.currentPage = pageNum;
    }
    if (scrollView == self.drugScrollerView) {
        NSInteger pageNum = self.drugScrollerView.contentOffset.x / WIDTH;
        self.drugPageControl.currentPage = pageNum;
    }
    if (scrollView == self.foodScrollerView) {
        NSInteger pageNum = self.foodScrollerView.contentOffset.x / WIDTH;
        self.foodPageControl.currentPage = pageNum;
    }
    if (scrollView == self.dieaseScrollerView) {
        NSInteger pageNum = self.dieaseScrollerView.contentOffset.x / WIDTH;
        self.dieasePageControl.currentPage = pageNum;
    }
}

//医疗新闻轮播区点击方法
- (void)tapAction:(UITapGestureRecognizer *)tap
{
    DetailNewsViewController *denewVC = [[DetailNewsViewController alloc] init];
    for (NSInteger i = 0; i < self.meiArr.count; i++) {
        if (self.medScrollerView.contentOffset.x == WIDTH*i) {
            denewVC.titleName = [self.meiArr[i] title];
            denewVC.myID = [self.meiArr[i]id];
            [self.navigationController pushViewController:denewVC animated:YES];
        }
    }
}

//生活贴士轮播区点击方法
- (void)tapActionLIfe:(UITapGestureRecognizer *)tap
{
    DetailNewsViewController *denewVC = [[DetailNewsViewController alloc] init];
    for (NSInteger i = 0; i < self.lifeArr.count; i++) {
        if (self.lifeScrollerView.contentOffset.x == WIDTH*i) {
            denewVC.titleName = [self.lifeArr[i] title];
            denewVC.myID = [self.lifeArr[i]id];
            [self.navigationController pushViewController:denewVC animated:YES];
        }
    }
}

//药品新闻轮播去点击方法
- (void)tapActiondrug:(UITapGestureRecognizer *)tap
{
    DetailNewsViewController *denewVC = [[DetailNewsViewController alloc] init];
    for (NSInteger i = 0; i < self.drugArr.count; i++) {
        if (self.drugScrollerView.contentOffset.x == WIDTH*i) {
            denewVC.titleName = [self.drugArr[i] title];
            denewVC.myID = [self.drugArr[i]id];
            [self.navigationController pushViewController:denewVC animated:YES];
        }
    }
}

//食品新闻轮播区点击方法
- (void)tapActionfood:(UITapGestureRecognizer *)tap
{
    DetailNewsViewController *denewVC = [[DetailNewsViewController alloc] init];
    for (NSInteger i = 0; i < self.foodArr.count; i++) {
        if (self.foodScrollerView.contentOffset.x == WIDTH*i) {
            denewVC.titleName = [self.foodArr[i] title];
            denewVC.myID = [self.foodArr[i]id];
            [self.navigationController pushViewController:denewVC animated:YES];
        }
    }
}

//疾病快讯轮播区点击方法
- (void)tapActiondiease:(UITapGestureRecognizer *)tap
{
    
    DetailNewsViewController *denewVC = [[DetailNewsViewController alloc] init];
    for (NSInteger i = 0; i < self.dieaseArr.count; i++) {
        if (self.dieaseScrollerView.contentOffset.x == WIDTH*i) {
            denewVC.titleName = [self.dieaseArr[i] title];
            denewVC.myID = [self.dieaseArr[i]id];
            [self.navigationController pushViewController:denewVC animated:YES];
        }
    }

}
//医药新闻上拉加载
-(void)medpullup
{
    [self.medTableView addLegendFooterWithRefreshingBlock:^{
        AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
        [manager GET:[NSString stringWithFormat:@"http://api.yi18.net/news/list?page=%ld&limit=20&id=2",self.medPage] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
            NSMutableDictionary *dic = responseObject;
            NSMutableArray *arr = dic[@"yi18"];
            for (NSMutableDictionary *temp in arr) {
                Medicine *medicine = [[Medicine alloc] init];
                [medicine setValuesForKeysWithDictionary:temp];
                [self.metableArr addObject:medicine];
            }
            for (int i = 0; i < self.metableArr.count; i++) {
                if ([self.metableArr[i]img] == nil) {
                    [self.metableArr removeObjectAtIndex:i];
                }
            }
            [self.medTableView reloadData];
            [self.medTableView.legendFooter endRefreshing];
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSLog(@"请求失败");
        }];
        self.medPage++;
        [self.medTableView reloadData];
        [self.medTableView.footer endRefreshing];
    }];
}

//生活贴士上拉加载
- (void)lifepullup
{
    [self.LifeTbaleView addLegendFooterWithRefreshingBlock:^{
        AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
        [manager GET:[NSString stringWithFormat:@"http://api.yi18.net/news/list?page=%ld&limit=20&id=3",self.lifePage] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
            NSMutableDictionary *dic = responseObject;
            NSMutableArray *arr = dic[@"yi18"];
            for (NSMutableDictionary *temp in arr) {
                Life *life = [[Life alloc] init];
                [life setValuesForKeysWithDictionary:temp];
                [self.lifetableArr addObject:life];
            }
            for (int i = 0; i < self.lifetableArr.count; i++) {
                if ([self.lifetableArr[i]img] == nil) {
                    [self.lifetableArr removeObjectAtIndex:i];
                }
            }
            [self.LifeTbaleView reloadData];
            [self.LifeTbaleView.legendFooter endRefreshing];
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSLog(@"请求失败");
        }];
        self.lifePage++;
        [self.LifeTbaleView reloadData];
        [self.LifeTbaleView.footer endRefreshing];
    }];
}

//药品新闻上拉加载
- (void)drugpullup
{
    [self.drugTbaleView addLegendFooterWithRefreshingBlock:^{
        AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
        [manager GET:[NSString stringWithFormat:@"http://api.yi18.net/news/list?page=%ld&limit=20&id=4",self.drugPage] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
            NSMutableDictionary *dic = responseObject;
            NSMutableArray *arr = dic[@"yi18"];
            for (NSMutableDictionary *temp in arr) {
                Drug *drug = [[Drug alloc] init];
                [drug setValuesForKeysWithDictionary:temp];
                [self.drugtableArr addObject:drug];
            }
            for (int i = 0; i < self.drugtableArr.count; i++) {
                if ([self.drugtableArr[i]img] == nil) {
                    [self.drugtableArr removeObjectAtIndex:i];
                }
            }
            [self.drugTbaleView reloadData];
            [self.drugTbaleView.legendFooter endRefreshing];
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSLog(@"请求失败");
        }];
        self.drugPage++;
        [self.drugTbaleView reloadData];
        [self.drugTbaleView.footer endRefreshing];
    }];
}

//食品新闻上拉加载
- (void)foodpullup
{
    [self.foodTbaleView addLegendFooterWithRefreshingBlock:^{
        AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
        [manager GET:[NSString stringWithFormat:@"http://api.yi18.net/news/list?page=%ld&limit=20&id=5",self.foodPage] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
            NSMutableDictionary *dic = responseObject;
            NSMutableArray *arr = dic[@"yi18"];
            for (NSMutableDictionary *temp in arr) {
                foodModel *food = [[foodModel alloc] init];
                [food setValuesForKeysWithDictionary:temp];
                [self.foodtableArr addObject:food];
            }
            for (int i = 0; i < self.foodtableArr.count; i++) {
                if ([self.foodtableArr[i]img] == nil) {
                    [self.foodtableArr removeObjectAtIndex:i];
                }
            }
            [self.foodTbaleView reloadData];
            [self.foodTbaleView.legendFooter endRefreshing];
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSLog(@"请求失败");
        }];
        self.foodPage++;
        [self.foodTbaleView reloadData];
        [self.foodTbaleView.footer endRefreshing];
    }];
}

//疾病快讯上拉加载
- (void)dieasepullup
{
    
    [self.dieaseTbaleView addLegendFooterWithRefreshingBlock:^{
        AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
        [manager GET:[NSString stringWithFormat:@"http://api.yi18.net/news/list?page=%ld&limit=20&id=7",self.dieasePage] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
            NSMutableDictionary *dic = responseObject;
            NSMutableArray *arr = dic[@"yi18"];
            for (NSMutableDictionary *temp in arr) {
                DiseaseModel *diease = [[DiseaseModel alloc] init];
                [diease setValuesForKeysWithDictionary:temp];
                [self.dieasetableArr addObject:diease];
            }
            for (int i = 0; i < self.dieasetableArr.count; i++) {
                if ([self.dieasetableArr[i]img] == nil) {
                    [self.dieasetableArr removeObjectAtIndex:i];
                }
            }
            [self.dieaseTbaleView reloadData];
            [self.dieaseTbaleView.legendFooter endRefreshing];
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSLog(@"请求失败");
        }];
        self.dieasePage++;
        [self.dieaseTbaleView reloadData];
        [self.dieaseTbaleView.footer endRefreshing];
    }];
 
}

- (void)clickLeftBu
{
    if (self.LeftBuIsClick == YES) {
    self.SmallView.hidden = NO;
        self.backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5*WIDTH, HEIGHT)];
        [self.view addSubview:self.backView];
        self.backView.userInteractionEnabled = YES;
        // 手势
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionback:)];
        //设置需要点击几次才会触发方法
        tap.numberOfTapsRequired = 1;
        // 设置手指个数
        tap.numberOfTouchesRequired = 1;
//         把手势加入到图片上
        [_backView addGestureRecognizer:tap];
        [self.view bringSubviewToFront:self.SmallView];
        self.LeftBuIsClick = NO;
    }else{
        self.SmallView.hidden = YES;
        [self.backView removeFromSuperview];
        self.LeftBuIsClick = YES;
    }
}

- (void)tapActionback:(UITapGestureRecognizer *)tap
{
    if (self.LeftBuIsClick == NO) {
        self.SmallView.hidden = YES;
        [self.backView removeFromSuperview];
        self.LeftBuIsClick = YES;
    }
}

- (void)clickRightBu
{
    SeacherViewController *searchVC = [[SeacherViewController alloc] init];
    [self.navigationController pushViewController:searchVC animated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
